package com.ts.api.module.channel.entity.bo;

import com.ts.api.common.constant.channel.ChannelFlowEnum;
import lombok.Data;

/**
 *  渠道用户业务实体
 */
@Data
public class ChannelUserBO {

    /** 用户id */
    private Long userId;
    /** 用户手机号 */
    private String phone;
    /** 注册流程 */
    private int hasRegister;
    /** 表单流程 */
    private int hasForm;
    /** 匹配机构流程 */
    private int hasOrg;
    /** 最后流程 */
    private int hasEndFlow;

    public ChannelUserBO() {
        super();
    }

    public ChannelUserBO(Long userId, String phone) {
        this.userId = userId;
        this.phone = phone;
    }

    public ChannelUserBO(Long userId, String phone, ChannelFlowEnum flowEnum) {
        this.userId = userId;
        this.phone = phone;
        setFlow(flowEnum);
    }

    /**
     * 自动设置流程
     *
     * @param flowEnum
     */
    public void setFlow(ChannelFlowEnum flowEnum) {
        switch (flowEnum) {
            case REGISTER:
                this.setHasRegister(suc());
                break;
            case FORM:
                this.setHasForm(suc());
                break;
            case ORG:
                this.setHasOrg(suc());
                break;
            case END_FLOW:
                this.setHasEndFlow(suc());
                break;
        }
    }

    /**
     * 成功
     *
     * @return int
     */
    public int suc() {
        return 1;
    }

    /**
     * 失败
     *
     * @return int
     */
    public int fail() {
        return 0;
    }

    /**
     * 转换状态模型
     *
     * @return
     */
    public String convertStateMode() {
        StringBuilder builder = new StringBuilder();
        builder.append(this.getHasRegister())
                .append(this.getHasForm())
                .append(this.getHasOrg())
                .append(this.getHasEndFlow());
        return builder.toString();
    }

}
